package Mailbox;

import java.net.Socket;
import java.util.Vector;

public class Mailbox {
	private String message = "";
	private boolean isSet = false;

	public synchronized void saveMessage(String message) {
		while (isSet) {
			try {
				wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}

		this.message = message;
		isSet = true;
		notifyAll();

	}

	public synchronized String removeMessage() {
		while (!isSet) {
			try {
				wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}

		String temp = message;
		message = "";
		isSet = false;
		notifyAll();

		return temp;

	}

}